
# Create the list of man pages for translation.
# This replicates the logic in top-level directory
# Including conditional installs

src_MANS = $(wildcard $(top_srcdir)/man/*.[1-9])

inst_MANS = \
	../man/free.1 \
	../man/pgrep.1 \
	../man/pkill.1 \
	../man/pmap.1 \
	../man/uptime.1 \
	../man/vmstat.8 \
	../man/procps.3 \
	../man/procps_pids.3 \
	../man/procps_misc.3

if !CYGWIN
inst_MANS += \
	../man/pwdx.1 \
	../man/tload.1 \
	../man/sysctl.8 \
	../man/sysctl.conf.5 \
	../man/ps.1

if BUILD_PIDWAIT
inst_MANS += ../man/pidwait.1
endif
endif
if BUILD_PIDOF
inst_MANS += ../man/pidof.1
endif
if BUILD_KILL
inst_MANS += ../man/kill.1
endif
if BUILD_W
inst_MANS += ../man/w.1
endif
if WITH_NCURSES
inst_MANS += \
	../man/watch.1 \
	../man/top.1
if !CYGWIN
inst_MANS += \
	    ../man/slabtop.1 \
	    ../man/hugetop.1
endif
endif
if BUILD_SKILL
inst_MANS += \
	    ../man/skill.1 \
	    ../man/snice.1
endif


# *.po and *.pot are kept in VCS and generated by po4a-dist command
# translated/* are put in distribution but not found in VCS
#
# To update man page translations:
#   rm po-man/man.stamp
#   make -C po-man man.stamp
#
# To update the po and pot files:
#   make -C po-man update-po


translated_MANS = $(wildcard translated/*/*.[1-9])
translated_MAN_sections=$(subst .,,$(sort $(suffix $(translated_MANS))))

translated_langs = $(notdir $(wildcard translated/*))


EXTRA_DIST = po4a.cfg \
	     procps-man.pot \
	     $(translated_MANS)

# Extract the list of languages from the po4a config file.
LINGUAS_DIST = $(shell sed -ne 's/^.*\[po4a_langs\] \(.*\)$$/\1/p' $(srcdir)/po4a.cfg)

# If the user has not defined it let's use the default.
LINGUAS ?= $(LINGUAS_DIST)

PO4A_V = $(PO4A_V_@AM_V@)
PO4A_V_ = $(PO4A_V_@AM_DEFAULT_V@)
PO4A_V_0 = @echo "  PO4A   $@";

PO4A_OPTS = --srcdir $(srcdir) --destdir $(CURDIR) \
            --package-name $(PACKAGE) --package-version $(VERSION) \
            --msgid-bugs-address "Procps list <procps@freelists.org>"

all-local: all-local-@USE_PO4A@

all-local-no:
all-local-yes: man.stamp

# FIXME: Use a stamp file until po4a supports them internally.
man.stamp:
	@if test -z '$(PO4A)'; then \
		echo "error: You need to install the po4a package."; \
		exit 1; \
	fi
	$(PO4A_V) $(PO4A) $(PO4A_OPTS) --no-update $(srcdir)/po4a.cfg
	$(AM_V_at) touch $@

clean-local: clean-local-@USE_PO4A@

clean-local-no:
clean-local-yes:
	rm -rf $(LINGUAS_DIST)
	$(AM_V_at) rm -f man.stamp

.PHONY: update-po

procps-man.pot: $(src_MANS)
#	parafiles = $(patsubst %,-m%,$(subst :, ,$(src_MANS)))
#	parafiles = $(src_MANS:doc=Ente)
	po4a-gettextize -M utf8 --option groff_code=verbatim --option generated --option untranslated="a.RE,\|" --option unknown_macros=untranslated -f man $(patsubst %,-m%,$(subst :, ,$(src_MANS))) -p $@

update-po:
	@if test -z '$(PO4A)'; then \
		echo "error: You need to install the po4a package."; \
		exit 1; \
	fi
	$(PO4A_V) $(PO4A) $(PO4A_OPTS) --no-translations --force $(srcdir)/po4a.cfg

install-data-local:
	for lang in $(LINGUAS) ; do \
	    files=""; \
	    for trans in $(notdir $(inst_MANS)); do \
		if [ -f $(CURDIR)/$$lang/$$trans ]; then \
		    files="$$files $(CURDIR)/$$lang/$$trans"; \
		elif [ -f $(srcdir)/$$lang/$$trans ]; then \
		    files="$$files $(srcdir)/$$lang/$$trans"; \
		fi; \
	    done; \
	    $(MAKE) -C .. install-man \
	            mandir="$(mandir)/$$lang" \
		    dist_man_MANS="$$files"; \
	done

uninstall-local:
	for lang in $(LINGUAS); do \
		files=""; \
		for trans in $(notdir $(inst_MANS)); do \
			if [ -f $(CURDIR)/$$lang/$$trans ]; then \
				files="$$files $(CURDIR)/$$lang/$$trans"; \
			elif [ -f $(srcdir)/$$lang/$$trans ]; then \
				files="$$files $(srcdir)/$$lang/$$trans"; \
			fi; \
		done; \
		$(MAKE) -C .. uninstall-man \
			mandir="$(mandir)/$$lang" \
			dist_man_MANS="$$files"; \
	done

dist-hook: man.stamp
	cp $(srcdir)/man.stamp $(distdir)/
	for lang in $(LINGUAS_DIST); do \
		cp $(srcdir)/$$lang.po $(distdir); \
		cp $(srcdir)/$$lang.add $(distdir); \
		$(MKDIR_P) $(distdir)/$$lang; \
		cp -r $(srcdir)/$$lang $(distdir)/; \
	done
